package com.xfcy.blog.controller.system;



import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xfcy.blog.annotation.OperationLogger;
import com.xfcy.blog.common.R;
import com.xfcy.blog.dto.PageDTO;
import com.xfcy.blog.service.PageService;
import com.xfcy.blog.valid.AddGroup;
import com.xfcy.blog.valid.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Page)表控制层
 *
 * @author 晓风残月Lx
 * @since 2023-04-09 11:03:06
 */
@RestController
@RequestMapping("system/page")
@Api(tags = "页面管理")
public class PageController {

    @Resource
    private PageService pageService;

    @GetMapping("/list")
    @SaCheckLogin
    @ApiOperation(value = "页面列表", httpMethod = "GET", response = R.class, notes = "页面列表")
    public R list() {
        return pageService.listPage();
    }

    @OperationLogger(value = "修改页面信息")
    @PostMapping("update")
    @SaCheckPermission("/system/page/update")
    @ApiOperation(value = "修改页面信息", httpMethod = "POST", response = R.class, notes = "修改页面信息")
    public R update(@Validated(UpdateGroup.class) @RequestBody PageDTO pageDTO) {
        return pageService.updatePage(pageDTO);
    }

    @OperationLogger(value = "新增页面")
    @PostMapping(value = "/add")
    @SaCheckPermission("/system/page/add")
    @ApiOperation(value = "新增页面", httpMethod = "POST", response = R.class, notes = "新增页面")
    public R insert(@Validated(AddGroup.class) @RequestBody PageDTO pageDTO) {
        return pageService.insertPage(pageDTO);
    }

    @OperationLogger(value = "删除页面")
    @DeleteMapping(value = "/delete")
    @SaCheckPermission("/system/page/delete")
    @ApiOperation(value = "删除页面", httpMethod = "DELETE", response = R.class, notes = "删除页面")
    public R delete(Long id) {
        return pageService.deletePage(id);
    }



}

